package com.lego.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lego.bean.User;
import com.lego.service.UserService;
import com.lego.service.impl.UserServiceImpl;

@WebServlet("/modify.do")
public class ModifyUserInfoServlet extends HttpServlet {
		UserService us=new UserServiceImpl();
		ObjectMapper om = new ObjectMapper();
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("application/json;charset=utf-8");
		req.setCharacterEncoding("utf-8");
		int userId=0;
		try {
			userId=Integer.parseInt(req.getParameter("userId"));
			
		}catch (Exception e) {
			// TODO: handle exception
			System.out.println("没获取到Id");
		}
		String userPwd=req.getParameter("userPwd");
		System.out.println(userPwd);
		String userNick=req.getParameter("userNick");
		
		User user= new User(userId,userPwd,userNick);
		
		int rows=us.modifyUser(user);
		if(rows==1) {
			resp.getWriter().write(om.writeValueAsString(user));
		}
	}
}
